package com.talkweb.securitycamera.utils.eventlib.communicationevent.dispatch;

import com.talkweb.securitycamera.utils.eventlib.communicationevent.PhotoEvent;
import com.talkweb.securitycamera.utils.eventlib.communicationevent.PhotoEventManager;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;

/**
 * @version 1.0.1
 * @description: 后台线程分发器
 * @program: Gallery
 * @Author xiaozhijun
 * @Date 2020/12/24 10:12
 */
public class BackgroudDispatch implements IDispatch {

    private EventHandler eventHandler;

    @Override
    public synchronized void post(PhotoEvent event) {
        if (eventHandler == null) {
            eventHandler = new EventHandler(EventRunner.create(true));
        }
        eventHandler.postTask(() -> {
            PhotoEventManager.getInstance().post(event);
        });
    }
}
